package activity.AllAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hichip.campro.R;

import java.util.ArrayList;

import custom.TimeDomainView;

public class PlanDetailAdapter extends BaseAdapter {

    private ArrayList<String> array_str;
    private Context mContext;

    public PlanDetailAdapter(Context context, ArrayList<String> array_str) {
        this.array_str = array_str;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return array_str.size();
    }

    @Override
    public String getItem(int position) {
        return array_str.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_plan_detail, null);
            holder.tv_time_slot = convertView.findViewById(R.id.tv_time_slot);
            holder.tv_delete = convertView.findViewById(R.id.tv_delete);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String string = getItem(position);
        holder.tv_time_slot.setText(string);
        holder.tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDeleteListeners != null) {
                    onDeleteListeners.onDelete(position);
                }
//                array_str.remove(position);
//                notifyDataSetChanged();
            }
        });
        return convertView;
    }

    private class ViewHolder {
        TextView tv_time_slot;
        TextView tv_delete;
    }

    public void setOnDeleteListeners(OnDeleteListeners deleteListeners) {
        this.onDeleteListeners = deleteListeners;
    }

    private OnDeleteListeners onDeleteListeners;

    public interface OnDeleteListeners {
        void onDelete(int position);
    }

}
